<template>
	<view class="textList">
		<!-- 头部 -->
		<view class="homelife_head">
			<view v-for="(item,index) in headlist" :key="index" class="container_headbox" @click="Onhead(item)">
				<text :class="code == item.code?'head_titlea':'head_titleb'">{{item.title}}</text>
				<view v-if="code == item.code"></view>
			</view>
		</view>
		<!-- 数据 -->
		<LoadMore ref="LoadMore" id="LoadMore" :diffHeight="124" :initData="initData" @dataRefresh='dataRefresh'>
			<text></text>
			<view v-for="(item,index) in MessageList" :key="index" class="message_list">
				<template v-if="item.doctor_name">
					<view class="cleaning_is">
						<view class="cleaning_isbox">
							<view class="font14 font-323232 font-b">订单号:{{item.order_code}}</view>
							<view class="font14 font-969696">
								{{item.typename}}
							</view>
						</view>
						<text class="font13 font-969696">下单时间:{{item.createtime}}</text>
					</view>
					<view class="cleaning_bos cleaning">
						<image class="cleaning_image" mode="aspectFill" :src="http_img+item.doctor_img"></image>
						<view class="cleaning_box">
							<view class="font14 font-323232">{{item.doctor_name}}</view>
							<view class="font14 font-323232">{{item.academic_title_name}}</view>
							<view class="ellipsis font13 font-969696">问题描述:{{item.content?item.content:'暂无'}}</view>
						</view>
					</view>
				</template>
				<template v-else>
					<view class="font14 flex-row-start">
						<view class="font-969696 w100p" style="width: 130rpx;">就 诊 人:</view>
						<view class="flex-1">{{item.user_the_patient_info.name}}  {{item.user_the_patient_info.sex ==1 ?'男':'女'}}</view>
					</view>
					<view class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p" style="width: 130rpx;">订 单 号:</view>
						<view class="flex-1">{{item.order_code}}</view>
					</view>
					<view class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p" style="width: 130rpx;">下单时间:</view>
						<view class="flex-1">{{item.createtime}}</view>
					</view>
					<view class="font14 flex-row-start" style="margin-top: 10rpx;">
						<view class="font-969696 w100p" style="width: 130rpx;">问题描述:</view>
						<view class="flex-1">{{item.content?item.content:'暂无'}}</view>
					</view>
				</template>
				<view class="cleaning_onall">
					<view class="font-323232 cleaning_money">
						<text class="font11">订单金额 ￥</text>
						<text class="font14 font-b">{{item.pay_status==2?item.total_money:item.money}}</text>
					</view>
					<view class="cleaning_button">
						<view v-if="item.pay_status==2&&item.status=='normal'"
							@click.stop="Onpages('/pagesA/ask/payment?id='+item.order_code+'&type=tw')">去支付</view>
						<view v-if="item.pay_status==1&&item.status=='patient'"
							@click.stop="Onpages('/pagesA/message/chat?isDoc=0&cate=text&orderno='+item.order_code)">
							进入诊室</view>
						<view v-if="item.pay_status==1&&item.status =='end'"
							@click.stop="Onpages('/pagesA/common/evaluate?id=' + item.id + '&type=tw')">去评价</view>
						<view v-if="(item.status =='comment'||item.status =='end')&& item.pay_status==1"
							@click.stop="Onpages('/pagesA/message/chat?isDoc=0&cate=text&orderno='+item.order_code)">
							问诊记录</view>
						<view v-if="item.pay_status==1&&item.status !='end'"
							@click.stop="Onpages('/pagesA/my/seedinfo?id=' + item.order_code + '&type=tw')">订单详情</view>
						<!-- <view v-if="item.status =='comment'">已评论</view> -->
					</view>
				</view>
			</view>
		</LoadMore>
	</view>
</template>

<script>
	import LoadMore from "@/components/loadMore.vue";
	export default {
		components: {
			LoadMore
		},
		data() {
			return {
				code: 'normal1',
				http_img: this.$store.state.http_img, //图片地址
				//头部列表
				headlist: [{
						title: '待支付',
						id: 1,
						code: 'normal1',
					},
					{
						title: '待接诊',
						id: 2,
						code: 'normal2'
					},
					{
						title: '已接诊',
						id: 3,
						code: 'patient'
					},
					{
						title: '已拒诊',
						id: 8,
						code: 'refuse_patient'
					},
					{
						title: '已结束',
						id: 4,
						code: 'end',
					},
					{
						title: '已评论',
						id: 5,
						code: 'comment',
					},
					{
						title: '已取消',
						id: 6,
						code: 'cancel',
					},
					{
						title: '已退款',
						id: 7,
						code: 'refund',
					}
				],
				//传参数据
				initData: {
					url: 'listConsultationOrder', //接口
					//data里得传参
					param: {
						pay_status: '2',
						status: 'normal'
					},
				},
				MessageList: []
			}
		},
		onLoad: function(options) {
			if (options.type == 1) {
				this.initData.param.pay_status = 1
				this.initData.param.status = 'normal'
				this.code = 'normal2'
			}
		},
		methods: {
			//返回数据
			dataRefresh(e) {
				e.forEach(item => {
					if (item.pay_status == 2) {
						if (item.status == 'normal') {
							item.typename = '待支付'
						}
						if (item.status == 'cancel') {
							item.typename = '已取消'
						}
					} else if (item.pay_status == 1) {
						if (item.status == 'normal') {
							item.typename = '待接诊'
						}
						if (item.status == 'patient') {
							item.typename = '已接诊'
						}
						if (item.status == 'refuse_patient') {
							item.typename = '已拒诊'
						}
						if (item.status == 'end') {
							item.typename = '待评价'
						}
						if (item.status == 'comment') {
							item.typename = '已结束'
						}
						if (item.status == 'cancel') {
							item.typename = '已取消'
						}
						if (item.status == 'refund') {
							item.typename = '已退款'
						}
					}
					// item.createtime = this.$base.formatTime(new Date(item.createtime *
					// 	1000), "yyyy/MM/dd hh:mm:ss")
					item.createtime = this.$u.timeFormat(item.createtime, 'yyyy/mm/dd hh:MM:ss')
				})
				this.MessageList = e
			},
			//切换
			Onhead(res) {
				if (res.code == 'normal1') {
					this.initData.param.pay_status = 2
					this.initData.param.status = 'normal'
				}
				if (res.code == 'normal2') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'normal'
				}
				if (res.code == 'patient') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'patient'
				}
				if (res.code == 'refuse_patient') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'refuse_patient'
				}
				if (res.code == 'end') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'end'
				}
				if (res.code == 'comment') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'comment'
				}
				if (res.code == 'cancel') {
					this.initData.param.pay_status = ''
					this.initData.param.status = 'cancel'
				}
				if (res.code == 'refund') {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'refund'
				}
				this.MessageList = []
				this.code = res.code
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			//页面跳转
			Onpages(e) {
				uni.navigateTo({
					url: e,
				})
			},
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>